/*
 * @FileName: [JsonUtils.java]
 * 
 * @Package com.bci.pwtz.common
 * 
 * 
 * Copyright (c) 2011-2015 BCINFO Technology Limited Com.
 * All rights reserved.
 * 
 * This software is the confidential and proprietary
 * information of BCINFO Technology Limited Company
 * ("Confidential Information"). You shall not disclose
 * such Confidential Information and shall use it only
 * in accordance with the terms of the contract agreement
 * you entered into with RKY.
 * 
 * $Rev: 217 $
 * $LastChangedDate$
 * $LastChangedBy: huangb $
 * 
 * @category ICCARD
 * 
 * @version 1.1
 * 
 * @author $Author: huangb $
 * 
 * Change History:[Formatter: author date description] <br/>
 * 1
 * 2
 * 3
 */

package com.bci.pwtz.common.util;

import java.lang.reflect.Type;
import java.text.DateFormat;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

/**
 * 一句话描述 <br/>
 * <p>
 * Description:<br/>
 * <p>
 * TODO 详细描述
 * 
 * <p>
 * For Examples <br/>
 * 
 * <PRE>
 *      TODO 代码使用示例
 * </PRE>
 * <p>
 */
public class JsonUtils
{
    public static String bean2json(Object bean)
    {
        Gson gson = new GsonBuilder().registerTypeAdapter(java.util.Date.class, new UtilDateSerializer()).setDateFormat(DateFormat.LONG).setPrettyPrinting().create();
        return gson.toJson(bean);
    }

    public static <T> T json2bean(String json, Type type)
    {

        Gson gson = new GsonBuilder().registerTypeAdapter(

        java.util.Date.class, new UtilDateDeserializer())

        .setDateFormat(DateFormat.LONG).create();

        // gson = new Gson();

        return gson.fromJson(json, type);

    }

}